package cn.infinite.security.configuration;

import cn.infinite.security.filter.WxCodeAuthenticationFilter;
import cn.infinite.security.provider.WxCodeAuthenticationProvider;
import lombok.AllArgsConstructor;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;

@AllArgsConstructor
public class WxAuthenticationConfigurerAdapter extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    private WxCodeAuthenticationFilter wxCodeAuthenticationFilter;

    private WxCodeAuthenticationProvider wxCodeAuthenticationProvider;

    @Override
    public void configure(HttpSecurity builder) throws Exception {
        this.wxCodeAuthenticationFilter.setAuthenticationManager(builder.getSharedObject(AuthenticationManager.class));
        builder.authenticationProvider(this.wxCodeAuthenticationProvider).addFilter(this.wxCodeAuthenticationFilter);
    }
}
